<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>享送小哥</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
</head>

<body>
    <div class="aui-content vue" style="margin-top:5px;">
        <textarea placeholder="请输入您的宝贵意见…" class="opin-area" v-model="form.msg"></textarea>
        <div class="photo-box">
            <div class="z_file" style="margin-bottom:10px;" @click="uploadTap">
            </div>
            <div class="photo-box1">
                <img :src="item" v-for="item in pics">
            </div>
        </div>
        <input class="aui-btn aui-btn-info login-sub2 aui-margin-b-15 opin-btn" value="提交" type="submit" @click="submit">
    </div>
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/vue.js"></script>
    <script type="text/javascript" src="../script/app.js"></script>
    <script type="text/javascript">
        apiready = function() {
            vObj = new Vue({
                el: ".vue",
                data: {
                    pics: [],
                    form: {
                        type: 'feedback',
                        msg: '',
                        pics: []
                    }
                },
                methods: {
                    uploadTap: function() {
                        api.actionSheet({
                            cancelTitle: '取消',
                            buttons: ['相机拍摄', '相册选取']
                        }, function(ret, err) {
                            switch (ret.buttonIndex) {
                                case 1:
                                    api.getPicture({
                                        sourceType: 'camera',
                                        mediaValue: 'pic',
                                        allowEdit: true,
                                        quality: 50,
                                        targetWidth: 800,
                                        targetHeight: 800
                                    }, function(ret, err) {
                                        if (ret) {
                                            vObj.upload(ret);
                                        }
                                    });
                                    break;
                                case 2:
                                    api.getPicture({
                                        sourceType: 'album',
                                        mediaValue: 'pic',
                                        allowEdit: true,
                                        quality: 100,
                                        targetWidth: 300,
                                        targetHeight: 300
                                    }, function(ret, err) {
                                        if (ret) {
                                            vObj.upload(ret);
                                        }
                                    });
                                    break;
                                default:

                            }
                        });
                    },
                    upload: function(ret) {
                        app.request.post('Common/uploadImg', {
                            type: 'message'
                        }, {
                            image: ret.data
                        }, function(res) {
                            if (res.code == 200) {
                                vObj.pics.push(res.data.full_path);
                                vObj.form.pics.push(res.data.path);
                            } else {
                                app.error(res.message);
                            }
                        });
                    },
                    submit: function() {
                        if (this.form.msg == '') {
                            app.error('请输入反馈内容！');
                            return false;
                        }
                        if (this.form.pics.length > 0) {
                            this.form.pics = this.form.pics.join();
                        }
                        app.request.post('Common/message', this.form, {}, function(res) {
                            if (res.code == 200) {
                                api.alert({
                                    title: '提示',
                                    msg: '您的反馈已提交，我们会尽快处理！',
                                }, function(ret, err) {
                                    api.closeWin();
                                });
                            } else {
                                app.error(res.message);
                            }
                        })
                    }
                }
            })
        }
    </script>
</body>

</html>
